package com.sh.ndt.common;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.sql.Timestamp;
import java.sql.Date;
import java.text.SimpleDateFormat;

/**
 * Utility class to deal with Date types
 * 
 * @author Manjula N. Hosadurga
 */
public class DateUtil {
    
    static final String monthDayYearFormat = "MMM-dd-yyyy";
    static SimpleDateFormat dateFormatter = new SimpleDateFormat(monthDayYearFormat);
    static Calendar calInstance = GregorianCalendar.getInstance();
    
    public static Timestamp dateToTimestamp(int year, int month, int day) {
        calInstance .set(year, month, day);
        Timestamp timestamp = new java.sql.Timestamp(calInstance .getTimeInMillis());
        return timestamp;
    }
    
    public static Date getDate(int year, int month, int day) {
        calInstance .set(year, month, day);
        Date date = new Date(calInstance .getTimeInMillis());
        return date;
    }
    
    public static Date getSqlDate(java.util.Date tmpDate) {
        Date date = new Date(tmpDate.getTime());
        return date;
    }
    
    public static Date getTodaysDate() {
        java.util.Date todaysDate = new java.util.Date();
        return new Date(todaysDate.getTime());
    }
    
    public static String formatDate(java.util.Date date) {      
        return dateFormatter.format(date);  
    }
}
